/*
 * config.h
 *
 *  Created on: May 8, 2022
 *      Author: Abyss
 */

#ifndef INC_CONFIG_H_
#define INC_CONFIG_H_

#include "stm32g0xx_hal.h"
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//各句柄
extern UART_HandleTypeDef huart1,huart2,huart3;
extern TIM_HandleTypeDef htim1,htim16,htim17,htim15;

//各函数
int run();
int wifi_config();
int at_send(char *at,uint32_t timeout);
int wait(char str[],uint32_t timeout);
//开启led定时器输出
void WS_Load(void);
//关闭所有灯
void WS_CloseAll(void);
//设置单个灯的颜色
uint32_t WS281x_Color(uint8_t red, uint8_t green, uint8_t blue);
void WS281x_SetPixelColor( uint32_t GRBColor);
void WS281x_SetRGB(uint8_t rgb[]);
//rgb hsv互转
void rgb2hsv(uint8_t g, uint8_t r, uint8_t b, float *h, float *s, float *v);
void hsv2rgb(float h, float s, float v, uint8_t *g, uint8_t *r, uint8_t *b);

//个全局变量
extern uint8_t buffer,buffers[1024],buffer_flag,electric[24],electric_buffer,electric_cnt;
extern uint16_t buffer_cnt;
extern uint32_t sys_time;
extern char _ID[],_NAME[],_KEY[];

//连接腾讯云标志位与接收数据标志
extern int _TC,TCMQTTRCVPUB;
//按键标志
extern int key_status;

//灯珠  DMA 需要传输的数据
extern uint16_t pulse[176];

//数据拦截控制状态标志
enum TC_STATUS{
	TC_CONNECT = 0,
	TC_DISCONNECT
};

//按键状态
enum KEY_STATUS{
	KEY_NULL = 0,
	KEY_SHORT = 1,
	KEY_CENTER = 2,
	KEY_LONG = 3
};

//at返回状态
enum AT_STATUS{
	AT_OK = 0,
	AT_FAIL = 1,
	AT_TIMOUT = 2
};

//FLAG状态
enum FLAG{
	FLAG_FLASE= 0,
	FLAG_TRUE = 1
};

//定义数据

struct  DATA{
	//继电器开关
	uint8_t power_switch;
	//电流
	float current;
	//电压
	float voltage;
	//功率因素
	float power_factor;
	//有功功率
	float active_power;
	//视在功率
	float apparent_power;
	//累计电量
	double total_kwh;
	//倒计时
	uint32_t count_down;
};
extern struct DATA all_data;

//紫罗兰
extern uint8_t VIOLET[];
//白色
extern uint8_t WHITE[];
//黑色
extern uint8_t BLACK[];
//红色
extern uint8_t RED[];
//绿色
extern uint8_t GREEN[];
//蓝色
extern uint8_t BLUE[];
//青色
extern uint8_t CYAN[];
//紫色
extern uint8_t PURPLE[];


#endif /* INC_CONFIG_H_ */


